﻿/* 
 * Since 2008 - 2012
 */

package com.hh.bss.auth.dao.impl;

import java.util.*;

import com.hh.bss.auth.dao.*;
import com.hh.bss.auth.entity.*;
import com.hh.bss.auth.service.*;
import com.hh.bss.auth.vo.query.*;
import com.hh.bss.base.*;
import com.hh.bss.common.MapObjectRowMapper;
import com.hh.bss.common.page.*;
import com.hh.bss.common.page.impl.*;
import com.hh.bss.util.*;





import static com.hh.bss.util.ObjectUtils.*;

import org.springframework.stereotype.Repository;

@Repository
public class SystemRoleDataControlDaoImpl extends BaseHibernateDao<SystemRoleDataControl,java.lang.Integer>  implements SystemRoleDataControlDao<SystemRoleDataControl,java.lang.Integer>{

	public Class getEntityClass() {
		return SystemRoleDataControl.class;
	}
	
	public Page findPage(SystemRoleDataControlQuery query) {
        //XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
        // [column]为字符串拼接, {column}为使用占位符. [column]为使用字符串拼接,如username='[username]',偷懒时可以使用字符串拼接 
        // [column] 为PageRequest的属性
        
		
		    Class[] os={SystemRoleDataControlQuery.class};
    		Class property= org.springframework.beans.BeanUtils.findPropertyType(query.getField_type(), os);
        if (property!=null){
        	 if ("java.lang.String".equals(property.getName())){
	    			
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(),query.getQuery());
	    			
	    		}
	    		else if ("java.lang.Integer".equals(property.getName())){
	    			
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(), StringHelper.parseInteger(query.getQuery(), 0));
	    			
	    		}
	    		else if ("java.lang.Double".equals(property.getName())){
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(), StringHelper.parseDouble(query.getQuery(), 0));
	    		}
	    		else if ("java.util.Date".equals(property.getName())){
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(), DateHelper.toDate(query.getQuery(), DateHelper.DEFAULT_DATE_FORMAT));
	    		}
        }	 
        //生成sql2的原因是为了不喜欢使用xsqlbuilder的同学，请修改生成器模板，删除本段的生成
        StringBuffer sql = new StringBuffer();
		List values = new ArrayList();
		sql.append(" select * from ( ");
		sql.append(" select a.data_name dataName,ifnull(b.id,0) id,a.id dataId,ifnull(b.role_id,0) roleId,ifnull(b.gr,0) gr,ifnull(b.gu,0) gu,ifnull(b.gd,0) gd,ifnull(b.ar,0) ar,ifnull(b.au,0) au,ifnull(b.ad,0) ad,ifnull(b.cr,0) cr,ifnull(b.cu,0) cu,ifnull(b.cd,0) cd from system_role_data a ");
		sql.append(" left join  system_role_data_control b on (a.id=b.data_id and b.role_id=?) ");
		sql.append(" ) t where 1=1 ");
		 values.add(query.getRoleId());
		return super.getJdbcDao().createPage(sql.toString(),values.toArray(), new MapObjectRowMapper(), query.getPageSize(), query.getPageNumber());
	}
	

}
